on:
  push:
  pull_request:

jobs:
  build:
    runs-on: "${{ matrix.os }}"
    strategy:
      matrix:
        include:
          # - os: macos-latest
          #   target: x86_64-apple-darwin
          #   suffix: ""
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            suffix: ""
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            suffix: .exe
    steps:
      - uses: actions/checkout@v3
      - uses: actions/cache@v1
        with:
          path: ~/.cargo/registry
          key: "${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}"
      - uses: actions/cache@v1
        with:
          path: ~/.cargo/git
          key: "${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}"
      - uses: actions/cache@v1
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          # TODO: use rust-toolchain.toml
          toolchain: nightly-2023-03-04
          components: rust-src, rustc-dev, llvm-tools-preview
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release
      - uses: actions/upload-artifact@v3
        with:
          name: ygglkan-${{ matrix.target }}
          path: ./target/release/ygglkan${{ matrix.suffix }}
